package com.example.practice.adapter;

import java.util.List;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.practice.R;

public class StudyAdapter extends PagerAdapter {
	private List<Drawable> imageViews;
	private Activity context;
	public StudyAdapter(Activity context, List<Drawable> imageViews) {
		this.imageViews = imageViews;
		this.context = context;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return imageViews.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0 == arg1;
	}
	
	
	
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		  container.removeView((View)object);  
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_study, null);
		TextView textView = (TextView) view.findViewById(R.id.tv_enter);
		view.findViewById(R.id.bg).setBackgroundDrawable(imageViews.get(position));
		if(position == imageViews.size() -1 ){
			textView.setVisibility(View.VISIBLE);
			textView.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					context.finish();
				}
			});
		}else{
			textView.setVisibility(View.GONE);
		}
		container.addView(view);
		return view;
	}
	


}
